<?php
namespace Destroyer\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Menu extends Model
{
    use HasFactory;

    protected $table = 'system_menu';

    // 可以批量赋值属性
    protected $fillable = [
        'parent_id', 
        'type', 
        'title', 
        'icon',
        'code', 
        'name', 
        'path',
        'component',
        'is_hidden',
        'sort'
    ];


    public function getButtons(array $buttonKeys)
    {
        $buttons = [
            'store'   => ['parent_id' => $this->id, 'type'  => 'B', 'title' => '新增', 'name'  => "{$this->name}::store", 'is_hidden'=>'1'],
            'edit'    => ['parent_id' => $this->id, 'type'  => 'B', 'title' => '编辑', 'name'  => "{$this->name}::edit", 'is_hidden'=>'1'],
            'destroy' => ['parent_id' => $this->id, 'type'  => 'B', 'title' => '删除', 'name'  => "{$this->name}::destroy", 'is_hidden'=>'1'],
            'trashed' => ['parent_id' => $this->id, 'type'  => 'B', 'title' => '回收站', 'name'  => "{$this->name}::trashed", 'is_hidden'=>'1'],
            'restore' => ['parent_id' => $this->id, 'type'  => 'B', 'title' => '恢复数据', 'name'  => "{$this->name}::restore", 'is_hidden'=>'1'],
            'delete'  => ['parent_id' => $this->id, 'type'  => 'B', 'title' => '物理删除', 'name'  => "{$this->name}::delete", 'is_hidden'=>'1'],
        ];

        $newButtons = [];
        foreach ($buttons as $key => $value) {
            if( in_array($key, $buttonKeys) ){
                $newButtons[] = $value;
            }
        }

        return $newButtons;
    }
}
